package com.becca.cake.model.advert;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.multipart.MultipartFile;

import com.becca.cake.core.exception.ServiceException;

/**
 * 广告实体类
 * @copyright  尊星(上海)信息科技有限公司
 * @author 
 * @date 2016年5月27日 下午3:51:53
 */
public class AdvertModel  implements Serializable{
   
    private static final long serialVersionUID = 1L;
    
    private Integer            id;
    /**广告标题*/
    private String             advTitle;
    /**广告类型(0:商品首页 1:全部商品)*/
    private Byte             advType;
    /**广告图片url*/
    private String             advPicPath;
    /**数据来源类型(0:商品ID 1:链接地址)*/
    private Byte             advSourceType;
    /**来源*/
    private String             advSource;
    /**来源(adv_source_type为0时是商品ID)*/
    private String             advComboSource;
    /**来源(adv_source_type为1时是链接地址)*/
    private String             advTextSource;
    /**状态(0:禁用 1:正常)*/
    private Byte             advStatus;
    /**排序*/
    private Byte               advOrder;
    /**开始时间*/
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date               startDate;
    /**结束时间*/
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date               endDate;
    /**创建时间*/
    private Date               createdDate;
    /**创建人*/
    private String             createdName;
    /**修改时间*/
    private Date               updatedDate;
    /**修改人*/
    private String             updatedName;
    
    private String goodsName;
    
    /**应用类型(0:微信 1:web)*/
    private Byte               applicationType;
    
    /**广告状态：（禁用：0）*/
    public static final Byte ADV_STATUS_FORBIDDEN = 0;
    /**广告状态：（正常：1）*/
    public static final Byte ADV_STATUS_NOMAL = 1;
    /**广告类型(0:商品首页  )*/
    public static final Byte   ADV_TYPE_PAGEGOODS = 0;
    /**广告类型(1:全部商品页  )*/
    public static final Byte   ADV_TYPE_ALLGOODS  = 1;
    /**来源类型(0:商品ID  )*/
    public static final Byte   ADV_COMBO_SOURCE = 0;
    /**来源类型(1:链接地址  )*/
    public static final Byte   ADV_TEXT_SOURCE  = 1;
    
    /**广告编号不能为空*/
    public static final String ADVERT_NOT_NULL ="广告编号不能为空";
    /**广告信息不存在*/
    public static final String ADVERT_NOT_EXISTE ="广告信息不存在";
    /**广告标题不能为空*/
    public static final String ADVERT_TITILE_NULL ="广告标题不能为空";
    /**广告类型不能为空*/
    public static final String ADVERT_TYPE_NULL ="广告类型不能为空";
    /**广告图片不能为空*/
    public static final String ADVERT_PICPATH_NULL ="广告图片不能为空";
    /**广告数据来源类型不能为空*/
    public static final String ADVERT_SOURCETYPE_NULL ="广告数据来源类型不能为空";
    /**广告来源不能为空*/
    public static final String ADVERT_SOURCE_NULL ="广告来源不能为空";
    /**广告排序不能为空*/
    public static final String ADVERT_ORDER_NULL ="广告排序不能为空";
    /**广告开始时间不能为空*/
    public static final String ADVERT_STARTDATE_NULL ="广告开始时间不能为空";
    /**广告结束时间不能为空*/
    public static final String ADVERT_ENDDATE_NULL ="广告结束时间不能为空";
    /**广告状态不能为空*/
    public static final String ADVERT_STATUS_NULL ="广告状态不能为空";
    
    /**该广告已被禁用*/
    public static final String ADVERT_STATUS_FORBIDDEN_EXIST ="该广告已被禁用";
    /**该广告已启用*/
    public static final String ADVERT_STATUS_NOMAL_EXIST ="该广告已启用";
    
    /**未修改排序*/
    public static final String UPD_ORDER_NULL ="未修改排序";
    
    /**
     * 修改广告状态时校验
     * @param advertId
     * @param advStatus
     */
    public static void validAdvStatus(Integer advertId,String advStatus){
        if (advertId == null) {
            throw new ServiceException(AdvertModel.ADVERT_NOT_NULL);
        }
        if (advStatus == null) {
            throw new ServiceException(AdvertModel.ADVERT_STATUS_NULL);
        }
    }
    
    /**
     * 查询广告对象时校验ID是否为空
     * @param advertId
     */
    public static void validAdvId(Integer advertId){
        if (advertId == null) {
            throw new ServiceException(AdvertModel.ADVERT_NOT_NULL);
        }
    }
    
    /**
     * 添加、修改广告校验
     * 
     * @param advertModel
     * @param files
     */
    public static void validInsertOrUpdateAdvert(AdvertModel advertModel, MultipartFile files){
        if(advertModel == null){
            throw new ServiceException(AdvertModel.ADVERT_NOT_EXISTE);
        }
        if(StringUtils.isEmpty(advertModel.getAdvTitle())){
            throw new ServiceException(AdvertModel.ADVERT_TITILE_NULL);
        }
        if(advertModel.getAdvType() == null){
            throw new ServiceException(AdvertModel.ADVERT_TYPE_NULL);
        }
        if(advertModel.getId() == null && files.isEmpty()){
            throw new ServiceException(AdvertModel.ADVERT_PICPATH_NULL);
        }
        if(advertModel.getAdvSourceType() == null){
            throw new ServiceException(AdvertModel.ADVERT_SOURCETYPE_NULL);
        }
        if(StringUtils.isEmpty(advertModel.getAdvSource())){
            throw new ServiceException(AdvertModel.ADVERT_SOURCE_NULL);
        }
        if(advertModel.getAdvOrder() == null){
            throw new ServiceException(AdvertModel.ADVERT_ORDER_NULL);
        }
        
        if(advertModel.getStartDate() == null){
            throw new ServiceException(AdvertModel.ADVERT_STARTDATE_NULL);
        }
        if(advertModel.getEndDate() == null){
            throw new ServiceException(AdvertModel.ADVERT_ENDDATE_NULL);
        }
    }
    
    /**
     * 广告排序不能为空
     * @param list
     */
    public static void validUpdateOrders(List<AdvertModel> list){
       for (AdvertModel advertModel : list) {
           if(advertModel.getAdvOrder() == null){
               throw new ServiceException(AdvertModel.ADVERT_ORDER_NULL);
           }
       }
    }
   
    
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getAdvTitle() {
        return advTitle;
    }
    public void setAdvTitle(String advTitle) {
        this.advTitle = advTitle;
    }
    public Byte getAdvType() {
        return advType;
    }
    public void setAdvType(Byte advType) {
        this.advType = advType;
    }
    public String getAdvPicPath() {
        return advPicPath;
    }
    public void setAdvPicPath(String advPicPath) {
        this.advPicPath = advPicPath;
    }
    public Byte getAdvSourceType() {
        return advSourceType;
    }
    public void setAdvSourceType(Byte advSourceType) {
        this.advSourceType = advSourceType;
    }
    public String getAdvComboSource() {
        return advComboSource;
    }
    public void setAdvComboSource(String advComboSource) {
        this.advComboSource = advComboSource;
    }
    public String getAdvTextSource() {
        return advTextSource;
    }
    public void setAdvTextSource(String advTextSource) {
        this.advTextSource = advTextSource;
    }
    
    public String getAdvSource() {
        return advSource;
    }
    public void setAdvSource(String advSource) {
        this.advSource = advSource;
    }
    public Byte getAdvStatus() {
        return advStatus;
    }
    public void setAdvStatus(Byte advStatus) {
        this.advStatus = advStatus;
    }
    public Byte getAdvOrder() {
        return advOrder;
    }
    public void setAdvOrder(Byte advOrder) {
        this.advOrder = advOrder;
    }
    public Date getStartDate() {
        return startDate;
    }
    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }
    public Date getEndDate() {
        return endDate;
    }
    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }
    public Date getCreatedDate() {
        return createdDate;
    }
    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }
    public String getCreatedName() {
        return createdName;
    }
    public void setCreatedName(String createdName) {
        this.createdName = createdName;
    }
    public Date getUpdatedDate() {
        return updatedDate;
    }
    public void setUpdatedDate(Date updatedDate) {
        this.updatedDate = updatedDate;
    }
    public String getUpdatedName() {
        return updatedName;
    }
    public void setUpdatedName(String updatedName) {
        this.updatedName = updatedName;
    }
    public String getGoodsName() {
        return goodsName;
    }

    public void setGoodsName(String goodsName) {
        this.goodsName = goodsName;
    }

	public Byte getApplicationType()
	{
		return applicationType;
	}

	public void setApplicationType(Byte applicationType)
	{
		this.applicationType = applicationType;
	}
    
}
